#include <signal.h>
#include <stdio.h>
#include <unistd.h>

pid_t pid;
void fun1(int num) {
  if (pid == 0)
    kill(getppid(), SIGUSR1);
}
void fun2(int num) { printf("move to next station\n"); }
void fun3(int num) {
  if (pid == 0)
    kill(getppid(), SIGUSR2);
}
void fun4(int num) { printf("stop the buf\n"); }
void fun5(int num) {
  if (pid > 0)
    kill(pid, SIGUSR1);
}
void fun6(int num) {
  if (pid == 0) {

    printf("all get off the bus\n");
    kill(SIGKILL, getppid());
    raise(SIGKILL);
  }
}
int main(int argc, char *argv[]) {

  pid = fork();
  if (pid > 0) {
    printf("parent %d,child %d\n", getpid(), pid);
    signal(SIGUSR1, fun2);
    signal(SIGUSR2, fun4);
    signal(SIGTSTP, fun5);
    while (1) {
      pause();
    }
  } else if (pid == 0) {
    signal(SIGINT, fun1);
    signal(SIGQUIT, fun3);
    signal(SIGUSR1, fun6);
    while (1) {
      pause();
    }
  }

  return 0;
}
